﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.Web.ASPxUploadControl;
using Exhibition.RenderTemplete.Controls;
using Exhibition.Common.Helper;
using Exhibition.Dao.ViewModel;
using Exhibition.Service;

namespace Exhibition.Manage
{
    public partial class SiteDetail : BaseAdminPage
    {
        SiteModel model = new SiteModel();
        string RtnUrl = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request["RtnUrl"] != null)
            {
                RtnUrl = Request["RtnUrl"];
            }
            if (!IsPostBack)
            {
               
                hfId.Value = reqID.ToString();
                GetSite();
            }
        }
        private void GetSite()
        {

            model = CenterService.siteService.GetOneById(reqID);
            if (model != null)
            {

                //网站名称
                txtWebName.Value = model.WebName;

                //关键词
                txtWebKey.Value = model.WebKey;

                //描述
                txtWebDesc.Text = model.WebDesc;

                //站长邮箱
                txtWebEmail.Value = model.WebEmail;

                //邮箱密码
                txtEmailPwd.Value = model.EmailPwd;

                //网站logo
                hfPic.Value = model.WebLogo;
                spPic.InnerHtml = "<img src='" + model.WebLogoPath + "' width='160' height='120'/>";
                txtEndDate.Value = model.EndTime == null ? DateTime.Now.AddMonths(1).ToString("yyyy-MM-dd") : Convert.ToDateTime(model.EndTime).ToString("yyyy-MM-dd");
                emailReg.Text = model.EmailReg;
                smtpServer.Value = model.StmpServer;
                //网站Logo路径
                //txtWebLogoPath.Value = model.WebLogoPath.ToString();
            }

        }

        /// <summary>
        /// 保存一条数据
        /// <summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {

            model = string.IsNullOrEmpty(hfId.Value) || hfId.Value == "0" ? new SiteModel() : CenterService.siteService.GetOneById(Convert.ToInt32(hfId.Value));
            //网站名称
            model.WebName = txtWebName.Value;

            //关键词
            model.WebKey = txtWebKey.Value;

            //描述
            model.WebDesc = txtWebDesc.Text;

            //站长邮箱
            model.WebEmail = txtWebEmail.Value;

            //邮箱密码
            model.EmailPwd = txtEmailPwd.Value;
            model.CreateUserId = model.CreateUserId == 0 ? AdminUser.Id : model.CreateUserId;
            //网站logo
            model.WebLogo = hfPic.Value;

            model.EndTime = Convert.ToDateTime(txtEndDate.Value);
            model.IsDelete = 0;
            model.IsAsk = 0;
            model.EmailReg = emailReg.Text;
            model.StmpServer = smtpServer.Value;
            //网站Logo路径
            //model.WebLogoPath = txtWebLogoPath.Value;

            if (CenterService.siteService.Save(model) > 0)
            {
                if (!string.IsNullOrEmpty(RtnUrl))
                {
                    Response.Redirect(RtnUrl);
                }
                else
                {
                    JsHelper.Unblock(this, CommFunMsg.GetMessage("A0001", Lan.zh));
                }
            }
            else
            {
                JsHelper.Alert(this, CommFunMsg.GetMessage("E0001", Lan.zh));
            }

        }

    }
}



